package com.ynr.voucher.service.impl;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ynr.voucher.model.ExpenseModel;
import com.ynr.voucher.model.FaModel;
import com.ynr.voucher.model.InvoiceItemModel;
import com.ynr.voucher.model.InvoiceModel;
import com.ynr.voucher.service.IFADepreciationService;
import com.ynr.voucher.service.IFAMatchService;
import com.ynr.voucher.service.IVoucherInvoiceService;
import com.ynr.voucher.service.IVoucherService;

@Service
public class VoucherInvoiceServiceImpl implements IVoucherInvoiceService {

	private static final Logger logger = LoggerFactory.getLogger(VoucherInvoiceServiceImpl.class);
	
	@Autowired
	private IFAMatchService faMatchService;
	
	@Autowired
	private IFADepreciationService faDepreciationService;
	
	@Autowired
	private IVoucherService voucherService;
	
	@Override
	public void processInvoice(InvoiceModel invoice, Map<String, Object> companyMap) {
		String billDate = invoice.getBillDate();
		String fplx = invoice.getFplx();
		logger.debug("VoucherInvoiceServiceImpl processInvoice, billDate : {}, fplx : {}", billDate, fplx);
		for(InvoiceItemModel item : invoice.getGoodsData()) {
			//固定资产匹配
			FaModel faModel = faMatchService.faMatchService(item, companyMap, fplx);
			if(faModel != null) { //匹配到固定资产
				//生成固定资产折旧明细表
				faDepreciationService.generateDepreciation(invoice, item, companyMap, fplx, faModel, billDate);
				item.setFa(true);
			} 
		}
		voucherService.generateInvoiceVoucher(billDate, 1, invoice, companyMap);
	}

	@Override
	public void processExpense(Map<String, Object> companyMap, ExpenseModel expense) {
		voucherService.generateExpenseVoucher(companyMap, expense);
	}
	
	
	
}
